package com.lyw.i04collectionProblem.setSolution;

import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArraySet;

/**
 * set 集合的多线程问题贺解决方案
 *
 * @author lyw
 * @Date 2023/7/10-上午9:32
 */
public class SetProblem {

  public static void main(String[] args) {
    // java.util.ConcurrentModificationException 并发修改问题
//    Set<String> set = new HashSet<>();
    Set<String> set = new CopyOnWriteArraySet<>();

    for (int i = 0; i < 30; i++) {
      new Thread(() -> {
        set.add(UUID.randomUUID().toString().substring(0, 8));
        System.out.println(set);
      }, String.valueOf(i)).start();
    }
  }
}
